package com.coursebooking.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.coursebooking.model.Course;
import com.coursebooking.model.Material;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MaterialRepository extends BaseMapper<Material> {
    
    @Select("SELECT * FROM material WHERE course_id = #{courseId}")
    List<Material> selectByCourseId(Long courseId);
    
    @Select("SELECT * FROM material WHERE course_id = #{courseId} ORDER BY upload_time DESC")
    List<Material> selectByCourseIdOrderByUploadTimeDesc(Long courseId);
    
    // 为了保持兼容性，添加包装方法
    default List<Material> findByCourse(Course course) {
        return selectByCourseId(course.getId());
    }
    
    default List<Material> findByCourseOrderByUploadTimeDesc(Course course) {
        return selectByCourseIdOrderByUploadTimeDesc(course.getId());
    }
}